jQuery('.alert').hide();

<% if @action == "enter payment" %>
    <% if @invoice_has_deleted_clients.length > 0 %>
        jQuery(".alert.alert-error").show().find('span').html("Please recover clients for invoice(s) with invoice# <%= @invoice_has_deleted_clients.join(",") %> to enter payment");
    <% else %>
        window.location.href = "/payments/enter_payment?invoice_ids=<%= params[:invoice_ids].join(",") %>&from_invoices=true"
    <% end %>
<%else%>

<% unless params[:flag]%>
    <% if @action == "archived" or @action == "deleted" %>
        jQuery(".alert.alert-success").show().find('span').html("<%= escape_javascript @message %>");
    <%elsif @action == "paid invoices" %>
        jQuery(".alert.alert-error").show().find('span').html("You cannot pay paid invoices.");
    <%elsif @action == "invoices_with_payments" %>
        <%
         if params[:destroy_archived].present?
            status = 'destroy_archived'
         elsif params[:destroy].present?
            status = 'destroy'
         else
            status = ''
         end
        %>
        jQuery(".modal-body").html("<%= escape_javascript(render(:partial=>"invoices_with_payments",:locals=>{:invoices_with_payments =>@invoices_with_payments, action_to_perform: status})) %>");
        jQuery('#invoices_with_payments').modal('show');
    <%else%>
        jQuery(".alert.alert-success").show().find('span').html("Invoice(s) are <%= @action %> successfully.");
    <% end %>
<% end %>

<%if !params[:invoice_ids].blank? && @action != "paid invoices"%>
    jQuery('tbody#invoice_body').html('<%= escape_javascript(render :partial=>"invoice") %>');
<%end%>

// Enable/Disable action links(Archive,Delete,Recover). //

jQuery('#active_links').html('<%= escape_javascript render("filter_links") %>');
jQuery('#active_links a').removeClass('active');



jQuery('#select_all').attr('checked', false);

<%if @action != "paid invoices"%>
    jQuery('tfoot#paging_links').html('<%= escape_javascript render :partial => "application_partials/paging", :page => params[:page] %>');
    jQuery('#bulk_actions').html('<%= escape_javascript render("bulk_actions") %>');
    jQuery("table.table_listing").trigger('update');
    jQuery(".sent, .partial,.draft, .draft-partial, .paid, .disputed, .viewed").qtip();
//    jQuery(".text-overflow-class").ellipsis({row: 1});
<%end%>

jQuery('.top_links').hide();
<% if @action == "recovered from archived"%>
    jQuery('.send').parent("li").removeClass("grid_control_sep");
    jQuery('.recover_archived,.destroy_archived,.send').show();
    jQuery('.get_archived').addClass('active');
<% elsif @action == "recovered from deleted" %>
    jQuery('.recover_deleted').show().parent("li").removeClass("grid_control_sep");
    jQuery('.get_deleted').addClass('active');
<% elsif @action == "deleted from archived" %>
    jQuery('.send').parent("li").removeClass("grid_control_sep");
    jQuery('.recover_archived,.destroy_archived,.send').show();
    jQuery('#active_links a.get_archived').addClass('active');
<% elsif params[:destroy_archived].present?  %>
    jQuery('.send').parent("li").removeClass("grid_control_sep");
    jQuery('.recover_archived,.destroy_archived,.send').show();
    jQuery('#active_links a.get_archived').addClass('active');
<%else%>
    jQuery('.archive,.destroy,.payment,.send').show();
    jQuery('.get_actives').addClass('active');
<%end%>

<%end%>
bind_deleted_entry();